home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATETIME.SWG / 0017_TIME2.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  1KB  |  27 lines

  1. { PW>question, I want to declare Type Time as (Hour,Min).  Where hour and
  2.  PW>minute are predeifed Types 0..23 and 0..59 respectively.  I then take
  3.  PW>the Type Time and use it as a field in a Record.  How would I promt a
  4.  PW>user to enter the time?  Ie. Enter (date,min): ???  Is there a way to do
  5.  PW>this without reading a String and then Formatting it and changing it to
  6.  PW>Integers?
  7. }
  8.    It can be done, but it's probably not worth the efFort to process it that
  9. way. I do this a lot, and I allow entering the Time as hh:mm or hhmm, where
  10. it's simply a String.  then, I parse out the ":", if it exists, and do a couple
  11. of divide and mod operations to then convert it to seconds - and store it that
  12. way.  I also have a routine which will Format seconds into time.  I do this
  13. enough (I'm in the race timing business), that I've found it easy to do this
  14. throughout my system - and keep all data in seconds.  I have a
  15. parsing/conversion routine and a conversion/display routine in my global Unit.
  16. Something like this:
  17.  
  18. Var S     : String;
  19.     I,T,N : Word;
  20.  
  21.   Write ('Enter Time as hh:mm '); readln (S);
  22.   if Pos(':',S) > 0 then Delete (S,Pos(':',S),1); Val (S,I,N);
  23.   T := ((I div 100) * 3600) + ((I mod 100) * 60);
  24.  
  25.    There should be some error-checking in this, but I'm sure you can figure it
  26. out...
  27.